package com.archtecture.model.patterns;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.archtecture.model.exceptions.NegocioException;
import com.spgf.model.utils.AndroidUtil;

@SuppressWarnings("rawtypes")
public abstract class PadraoFragmentCad extends PadraoFragment implements
		Button.OnClickListener {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		try {
			configurarTela(inflater, container);
		} catch (NegocioException e) {
			Toast.makeText(rootView.getContext(),
					AndroidUtil.obterMensagemErro(e), Toast.LENGTH_SHORT)
					.show();
		}

		return rootView;
	}

	@Override
	public void onClick(final View pView) {

		try {
			executarClick(pView);
		} catch (final NegocioException e) {
			Toast.makeText(pView.getContext(),
					AndroidUtil.obterMensagemErro(e), Toast.LENGTH_LONG).show();
		}
	}

	protected void executarClick(View pView) throws NegocioException {
	}

	public abstract void configurarTela(LayoutInflater inflater,
			ViewGroup container) throws NegocioException;
}
